<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>png++: generator.hpp Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />



</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">png++
   &#160;<span id="projectnumber">0.2.1</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.6.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">generator.hpp</div>  </div>
</div><!--header-->
<div class="contents">
<a href="generator_8hpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> * Copyright (C) 2007,2008   Alex Shulgin</span>
<a name="l00003"></a>00003 <span class="comment"> *</span>
<a name="l00004"></a>00004 <span class="comment"> * This file is part of png++ the C++ wrapper for libpng.  PNG++ is free</span>
<a name="l00005"></a>00005 <span class="comment"> * software; the exact copying conditions are as follows:</span>
<a name="l00006"></a>00006 <span class="comment"> *</span>
<a name="l00007"></a>00007 <span class="comment"> * Redistribution and use in source and binary forms, with or without</span>
<a name="l00008"></a>00008 <span class="comment"> * modification, are permitted provided that the following conditions are met:</span>
<a name="l00009"></a>00009 <span class="comment"> *</span>
<a name="l00010"></a>00010 <span class="comment"> * 1. Redistributions of source code must retain the above copyright notice,</span>
<a name="l00011"></a>00011 <span class="comment"> * this list of conditions and the following disclaimer.</span>
<a name="l00012"></a>00012 <span class="comment"> *</span>
<a name="l00013"></a>00013 <span class="comment"> * 2. Redistributions in binary form must reproduce the above copyright</span>
<a name="l00014"></a>00014 <span class="comment"> * notice, this list of conditions and the following disclaimer in the</span>
<a name="l00015"></a>00015 <span class="comment"> * documentation and/or other materials provided with the distribution.</span>
<a name="l00016"></a>00016 <span class="comment"> *</span>
<a name="l00017"></a>00017 <span class="comment"> * 3. The name of the author may not be used to endorse or promote products</span>
<a name="l00018"></a>00018 <span class="comment"> * derived from this software without specific prior written permission.</span>
<a name="l00019"></a>00019 <span class="comment"> *</span>
<a name="l00020"></a>00020 <span class="comment"> * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS&#39;&#39; AND ANY EXPRESS OR</span>
<a name="l00021"></a>00021 <span class="comment"> * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES</span>
<a name="l00022"></a>00022 <span class="comment"> * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN</span>
<a name="l00023"></a>00023 <span class="comment"> * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,</span>
<a name="l00024"></a>00024 <span class="comment"> * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED</span>
<a name="l00025"></a>00025 <span class="comment"> * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR</span>
<a name="l00026"></a>00026 <span class="comment"> * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF</span>
<a name="l00027"></a>00027 <span class="comment"> * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING</span>
<a name="l00028"></a>00028 <span class="comment"> * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS</span>
<a name="l00029"></a>00029 <span class="comment"> * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span>
<a name="l00030"></a>00030 <span class="comment"> */</span>
<a name="l00031"></a>00031 <span class="preprocessor">#ifndef PNGPP_GENERATOR_HPP_INCLUDED</span>
<a name="l00032"></a>00032 <span class="preprocessor"></span><span class="preprocessor">#define PNGPP_GENERATOR_HPP_INCLUDED</span>
<a name="l00033"></a>00033 <span class="preprocessor"></span>
<a name="l00034"></a>00034 <span class="preprocessor">#include &lt;cassert&gt;</span>
<a name="l00035"></a>00035 <span class="preprocessor">#include &lt;stdexcept&gt;</span>
<a name="l00036"></a>00036 <span class="preprocessor">#include &lt;iostream&gt;</span>
<a name="l00037"></a>00037 <span class="preprocessor">#include &lt;ostream&gt;</span>
<a name="l00038"></a>00038 
<a name="l00039"></a>00039 <span class="preprocessor">#include &quot;<a class="code" href="config_8hpp.html">config.hpp</a>&quot;</span>
<a name="l00040"></a>00040 <span class="preprocessor">#include &quot;<a class="code" href="error_8hpp.html">error.hpp</a>&quot;</span>
<a name="l00041"></a>00041 <span class="preprocessor">#include &quot;<a class="code" href="streaming__base_8hpp.html">streaming_base.hpp</a>&quot;</span>
<a name="l00042"></a>00042 <span class="preprocessor">#include &quot;<a class="code" href="writer_8hpp.html">writer.hpp</a>&quot;</span>
<a name="l00043"></a>00043 
<a name="l00044"></a>00044 <span class="keyword">namespace </span>png
<a name="l00045"></a>00045 {
<a name="l00046"></a>00046 
<a name="l00112"></a>00112     <span class="keyword">template</span>&lt; <span class="keyword">typename</span> pixel,
<a name="l00113"></a>00113               <span class="keyword">class </span>pixgen,
<a name="l00114"></a>00114               <span class="keyword">class </span>info_holder = def_image_info_holder,
<a name="l00115"></a>00115               <span class="keywordtype">bool</span> interlacing_supported = <span class="keyword">false</span> &gt;
<a name="l00116"></a><a class="code" href="classpng_1_1generator.html">00116</a>     <span class="keyword">class </span><a class="code" href="classpng_1_1generator.html" title="Pixel generator class template.">generator</a>
<a name="l00117"></a>00117         : <span class="keyword">public</span> <a class="code" href="classpng_1_1streaming__base.html" title="A base class template for consumer and generator classes. Provides default reset() method implementat...">streaming_base</a>&lt; pixel, info_holder &gt;
<a name="l00118"></a>00118     {
<a name="l00119"></a>00119     <span class="keyword">public</span>:
<a name="l00128"></a>00128         <span class="keyword">template</span>&lt; <span class="keyword">typename</span> ostream &gt;
<a name="l00129"></a><a class="code" href="classpng_1_1generator.html#ab96a8e8e7050afddb307141d7cabb5eb">00129</a>         <span class="keywordtype">void</span> <a class="code" href="classpng_1_1generator.html#ab96a8e8e7050afddb307141d7cabb5eb" title="Writes an image to the stream.">write</a>(ostream&amp; stream)
<a name="l00130"></a>00130         {
<a name="l00131"></a>00131             <a class="code" href="classpng_1_1writer.html" title="PNG writer class template. This is the low-level writing interface--use image class or generator clas...">writer&lt; ostream &gt;</a> wr(stream);
<a name="l00132"></a>00132             wr.<a class="code" href="classpng_1_1io__base.html#a9e2c8aa9dbd7f398758a992c4857ca02">set_image_info</a>(this-&gt;<a class="code" href="classpng_1_1streaming__base.html#adab066b598745083ed1031f20f702faf">get_info</a>());
<a name="l00133"></a>00133             wr.<a class="code" href="classpng_1_1writer.html#a36bc62c0fe6d99dcec439fde2d54228c" title="Write info about PNG image.">write_info</a>();
<a name="l00134"></a>00134 
<a name="l00135"></a>00135 <span class="preprocessor">#if __BYTE_ORDER == __LITTLE_ENDIAN</span>
<a name="l00136"></a>00136 <span class="preprocessor"></span>            <span class="keywordflow">if</span> (pixel_traits&lt; pixel &gt;::get_bit_depth() == 16)
<a name="l00137"></a>00137             {
<a name="l00138"></a>00138 <span class="preprocessor">#ifdef PNG_WRITE_SWAP_SUPPORTED</span>
<a name="l00139"></a>00139 <span class="preprocessor"></span>                wr.<a class="code" href="classpng_1_1io__base.html#ae937edb8117961235667f808a3f88e3e">set_swap</a>();
<a name="l00140"></a>00140 <span class="preprocessor">#else</span>
<a name="l00141"></a>00141 <span class="preprocessor"></span>                <span class="keywordflow">throw</span> <a class="code" href="classpng_1_1error.html" title="Exception class to represent runtime errors related to png++ operation.">error</a>(<span class="stringliteral">&quot;Cannot write 16-bit image:&quot;</span>
<a name="l00142"></a>00142                             <span class="stringliteral">&quot; recompile with PNG_WRITE_SWAP_SUPPORTED.&quot;</span>);
<a name="l00143"></a>00143 <span class="preprocessor">#endif</span>
<a name="l00144"></a>00144 <span class="preprocessor"></span>            }
<a name="l00145"></a>00145 <span class="preprocessor">#endif</span>
<a name="l00146"></a>00146 <span class="preprocessor"></span>
<a name="l00147"></a>00147             <span class="keywordtype">size_t</span> pass_count;
<a name="l00148"></a>00148             <span class="keywordflow">if</span> (this-&gt;<a class="code" href="classpng_1_1streaming__base.html#adab066b598745083ed1031f20f702faf">get_info</a>().get_interlace_type() != <a class="code" href="namespacepng.html#a4b468278362e4ccf0b2c52f9c0692bdca173491c30047b28a7641cba46d97331a">interlace_none</a>)
<a name="l00149"></a>00149             {
<a name="l00150"></a>00150 <span class="preprocessor">#ifdef PNG_WRITE_INTERLACING_SUPPORTED</span>
<a name="l00151"></a>00151 <span class="preprocessor"></span>                <span class="keywordflow">if</span> (interlacing_supported)
<a name="l00152"></a>00152                 {
<a name="l00153"></a>00153                     pass_count = wr.<a class="code" href="classpng_1_1io__base.html#acdb6c2fe9e68f6ce2643131a21999279">set_interlace_handling</a>();
<a name="l00154"></a>00154                 }
<a name="l00155"></a>00155                 <span class="keywordflow">else</span>
<a name="l00156"></a>00156                 {
<a name="l00157"></a>00157                     <span class="keywordflow">throw</span> std::logic_error(<span class="stringliteral">&quot;Cannot write interlaced image:&quot;</span>
<a name="l00158"></a>00158                                            <span class="stringliteral">&quot; generator does not support it.&quot;</span>);
<a name="l00159"></a>00159                 }
<a name="l00160"></a>00160 <span class="preprocessor">#else</span>
<a name="l00161"></a>00161 <span class="preprocessor"></span>                <span class="keywordflow">throw</span> <a class="code" href="classpng_1_1error.html" title="Exception class to represent runtime errors related to png++ operation.">error</a>(<span class="stringliteral">&quot;Cannot write interlaced image:&quot;</span>
<a name="l00162"></a>00162                             <span class="stringliteral">&quot; interlace handling disabled.&quot;</span>);
<a name="l00163"></a>00163 <span class="preprocessor">#endif</span>
<a name="l00164"></a>00164 <span class="preprocessor"></span>            }
<a name="l00165"></a>00165             <span class="keywordflow">else</span>
<a name="l00166"></a>00166             {
<a name="l00167"></a>00167                 pass_count = 1;
<a name="l00168"></a>00168             }
<a name="l00169"></a>00169             pixgen* pixel_gen = <span class="keyword">static_cast&lt;</span> pixgen* <span class="keyword">&gt;</span>(<span class="keyword">this</span>);
<a name="l00170"></a>00170             <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> pass = 0; pass &lt; pass_count; ++pass)
<a name="l00171"></a>00171             {
<a name="l00172"></a>00172                 pixel_gen-&gt;reset(pass);
<a name="l00173"></a>00173 
<a name="l00174"></a>00174                 <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> pos = 0; pos &lt; this-&gt;<a class="code" href="classpng_1_1streaming__base.html#adab066b598745083ed1031f20f702faf">get_info</a>().<a class="code" href="classpng_1_1image__info.html#a640f6451351d62920fa2786dea53cd4d">get_height</a>(); ++pos)
<a name="l00175"></a>00175                 {
<a name="l00176"></a>00176                     wr.<a class="code" href="classpng_1_1writer.html#aa88beb256941e06e54e6842a1b0a81ee" title="Writes a row of image data at a time.">write_row</a>(pixel_gen-&gt;get_next_row(pos));
<a name="l00177"></a>00177                 }
<a name="l00178"></a>00178             }
<a name="l00179"></a>00179 
<a name="l00180"></a>00180             wr.<a class="code" href="classpng_1_1writer.html#a935ff64a683bb7d98961ff936976f52c" title="Reads ending info about PNG image.">write_end_info</a>();
<a name="l00181"></a>00181         }
<a name="l00182"></a>00182 
<a name="l00183"></a>00183     <span class="keyword">protected</span>:
<a name="l00184"></a><a class="code" href="classpng_1_1generator.html#afd0ec501ad497cd64b38d9edfb4a0ab6">00184</a>         <span class="keyword">typedef</span> <a class="code" href="classpng_1_1streaming__base.html" title="A base class template for consumer and generator classes. Provides default reset() method implementat...">streaming_base&lt; pixel, info_holder &gt;</a> <a class="code" href="classpng_1_1generator.html#afd0ec501ad497cd64b38d9edfb4a0ab6">base</a>;
<a name="l00185"></a>00185 
<a name="l00190"></a><a class="code" href="classpng_1_1generator.html#a9580193ea493f8b9d289caf349898395">00190</a>         <span class="keyword">explicit</span> <a class="code" href="classpng_1_1generator.html#a9580193ea493f8b9d289caf349898395" title="Constructs a generator object using passed image_info object to store image information.">generator</a>(<a class="code" href="classpng_1_1image__info.html" title="Holds information about PNG image.">image_info</a>&amp; <a class="code" href="classpng_1_1info.html" title="Holds information about PNG image. Adapter class for IO image operations.">info</a>)
<a name="l00191"></a>00191             : <a class="code" href="classpng_1_1streaming__base.html">base</a>(info)
<a name="l00192"></a>00192         {
<a name="l00193"></a>00193         }
<a name="l00194"></a>00194 
<a name="l00199"></a><a class="code" href="classpng_1_1generator.html#a45d4289aaa3bffe7ae8065cb7c28220a">00199</a>         <a class="code" href="classpng_1_1generator.html#a9580193ea493f8b9d289caf349898395" title="Constructs a generator object using passed image_info object to store image information.">generator</a>(<span class="keywordtype">size_t</span> width, <span class="keywordtype">size_t</span> height)
<a name="l00200"></a>00200             : <a class="code" href="classpng_1_1streaming__base.html">base</a>(width, height)
<a name="l00201"></a>00201         {
<a name="l00202"></a>00202         }
<a name="l00203"></a>00203     };
<a name="l00204"></a>00204 
<a name="l00205"></a>00205 } <span class="comment">// namespace png</span>
<a name="l00206"></a>00206 
<a name="l00207"></a>00207 <span class="preprocessor">#endif // PNGPP_GENERATOR_HPP_INCLUDED</span>
</pre></div></div><!-- contents -->


<hr class="footer"/><address class="footer"><small>
Generated on Fri Jan 25 2013 14:10:10 for png++ by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.6.1
</small></address>

</body>
</html>
